package com.softcomputer.rpt.ejb;

import com.softcomputer.rpt.entity.ExCourse;
import com.softcomputer.rpt.generated.GeneratedExCourse;
import com.softcomputer.rpt.interfaces.Echo;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;

@Stateless
@WebService(targetNamespace = "http://ejb.rpt.softcomputer.com/")
public class WebServiceBean implements Echo {

    @EJB
    private CoursesDBSession coursesDBSession;

    @Override
    @WebMethod(operationName = "echo")
    public String echo(String s) {
        return "Test echo + " + s;
    }

    @Override
    @WebMethod(operationName = "processExCourse")
    public String processExCourse(GeneratedExCourse generatedExCourse) {

        ExCourse newCourse = new ExCourse(
                generatedExCourse.getId(),
                generatedExCourse.getCurrency(),
                generatedExCourse.getIndollars());

        coursesDBSession.saveCourseToDatabase(newCourse);

        return "Processed: " + newCourse.toString();
    }
}
